---
category: DOM
created: '2021-04-21'
title: Get the position of an element relative to the document
updated: '2021-10-13'
---

**JavaScript version**

```js getPosition.js
const getPosition = (ele) => (
    (r = ele.getBoundingClientRect()), { left: r.left + window.scrollX, top: r.top + window.scrollY }
);
```

**Example**

```js example.js
getPosition(document.body); // { left: 0, top: 0 }
```
